package com.itheima.restkeeper.strategy.impl;

import com.itheima.restkeeper.constant.TradingConstant;
import com.itheima.restkeeper.strategy.TradingStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;

/**
 * @Description: 策略具体实现类
 * @Version: V1.0
 */
@Component
public class TradingStrategyImpl {

    @Autowired
    TradingStrategy creditTradingStrategy;
    @Autowired
    TradingStrategy fkTradingStrategy;
    @Autowired
    TradingStrategy freeTradingStrategy;
    @Autowired
    TradingStrategy tkTradingStrategy;

    private static final HashMap<String, TradingStrategy> map = new HashMap<>();

    @PostConstruct
    public void init() {
        map.put(TradingConstant.TRADING_TYPE_FK, fkTradingStrategy);
        map.put(TradingConstant.TRADING_TYPE_TK, tkTradingStrategy);
        map.put(TradingConstant.TRADING_TYPE_GZ, creditTradingStrategy);
        map.put(TradingConstant.TRADING_TYPE_MD, freeTradingStrategy);
    }

    /**
     * 根据支付类型转换交易单
     *
     * @param type
     * @return
     */
    public TradingStrategy convert(String type) {
        return map.get(type);
    }

}
